﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Threading;
using System.Windows.Forms;

using GeneralTool.CoreLibrary.Extensions;
using GeneralTool.CoreLibrary.IniHelpers;
using GeneralTool.CoreLibrary.Licenses;
using GeneralTool.CoreLibrary.Models;
using GeneralTool.CoreLibrary.TaskLib;

using SocketTest.IniCommon;

namespace SocketTest
{
    internal class Program
    {
        //DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
        //static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);

        [DllImport("user32.dll",EntryPoint ="ShowWindow",SetLastError =true)]
        static extern bool ShowWindow(IntPtr intPtr,uint dwDesiredSize);



        [DllImport("User32.dll", EntryPoint = "FindWindow")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        static void Main(string[] args)
        {
            new PackageTest().Test();
            Console.ReadKey();
            new CameraTest().Test();
            //var client = new FixedHeadSocketClient(null, null);
            //client.Startup("192.168.31.211", 5382);
            //var r = client.SendResultObject<string>(new ServerRequest()
            //{
            //    Url = "DeviceTask/GetCameraImage",
            //    Parameters = { { "mode", 1 } }
            //}, CancellationToken.None);


            byte[] buffer = { 0x66 , 0xcc , 0x10 , 0xb1 , 0x03 , 0x02 , 0xa7 , 0x08 , 0x01 , 0xff , 0xc9 , 0x20 , 0x10 , 0x31 , 0x6b , 0xf5 };

            byte b = 0;
            for (int i = 0; i < buffer.Length; i++)
                b = (byte)(b + buffer[i]);


            string folderPath = @"E:\BaiduNetdiskDownload";

            var ps = Process.GetProcesses();
            var process = Process.GetProcessesByName("explorer");
            foreach (var pro in process)
            {
                if (pro.MainWindowTitle == folderPath)
                {
                    
                }
            }

            //new IOCTest().Test();
            //var color = "Blue".ToDrawingColor();
            //var str = color.ToHexString();

            //var dir = "\\aa\\bb\\cc";
            //dir.CreateDirectory();

            //var client = new FixedHeadSocketClient(null, null);
            //client.Client.ReceiveBufferSize = 1024 * 1024 * 10;
            //client.ReadTimeOut = 18000;

            //while (true)
            //{
            //    client.Startup("127.0.0.1", 8877);
            //    client.Send(new ServerRequest()
            //    {
            //        Url = "Task/TestString"
            //    }, System.Threading.CancellationToken.None);
            //    System.Threading.Thread.Sleep(100);
            //}
            //client.Dispose();

            //var ini = new SimpleIniManager();
            //ini.SetValue("Window", "abc",33);
            //var a = ini.GetValue("Window", "abc");

            //var file = new MemoryStream();
            //SingleInstance<MemoryStream>.SetInstanceFunc(() => file);

            //var f = SingleInstance<MemoryStream>.GetInstance(() => file);

            //var model = SingleInstance<Model>.Instance;
            //model.X = 100;
            //var m2 = SingleInstance<Model>.Instance;

            //var node = new WindowNode(nameof(WindowNode));
            //var width = node.Width.Value;
            //node.Width.Value = 2;

            var node = new WindowNode(nameof(WindowNode));
            node.Boolean.Value = false;
            var value = node.Boolean.Value;
            node.Str.Value = "str";
            var str = node.Str.Value;

            node.Boolean.Value = false;
            var b1 = node.Boolean.Value;

            node.Height.Value = 100d;
            var h = node.Height.Value;

            node.Width.Value = 200;
            var w = node.Width.Value;

            node.DataAccessKindValue.Value = Microsoft.SqlServer.Server.DataAccessKind.Read;
            var dd = node.DataAccessKindValue.Value;

            //var value = node.DataAccessKindValue.Value;
            //node.DataAccessKindValue.Value = Microsoft.SqlServer.Server.DataAccessKind.None;
            //value = node.DataAccessKindValue.Value;

            //var value = node.Boolean.Value;
            //node.Boolean.Value = false;
            //value = node.Boolean.Value;

            //var t = new int[] { 1, 2, 3 };
            //var s = t.Slince(3, 2);
            //var s1 = s.ToList();
            //var c1 = new Class1();
            //c1.C1();
            //c1.C3();

            //c1.C2();

            //c1.Remove();

            //var buffer= LicenseManager.CreateLicense(null, DateTime.Now.AddDays(1));
            //File.WriteAllText("lic.dll", LicenseManager.Encode(buffer));
            //LicenseManager.Verity("lic.dll");

            //System.Console.WriteLine("11");

            //BindingFlags bindingFlags = BindingFlags.Static | BindingFlags.Public;
            //var types = new Type[] { typeof(string) };
            //types = null;
            //var parameterModifier = new ParameterModifier[] { new ParameterModifier(1) };
            //parameterModifier = null;
            //var oldMethod = typeof(TestClass).GetMethod(nameof(TestClass.WriteLine),
            //    bindingFlags,
            //    null,
            //    CallingConventions.Standard,
            //    types,
            //    parameterModifier);
            //var newMethod = typeof(Program).GetMethod(nameof(Program.WriteLine),
            //    bindingFlags,
            //    null,
            //    CallingConventions.Standard,
            //    types,
            //    parameterModifier);

            //ReplaceMethod(oldMethod, newMethod);

            TestClass.WriteLine();
            WriteLine();

          
            Console.ReadKey();
        }

        public static void WriteLine()
        {
            Console.WriteLine("Program");
        }

      
        private static void FooStatic()
        {
            Console.WriteLine("FooStatic");
        }
    }

    class Class1
    {
        public void Demo()
        {
            Console.WriteLine("Demo");
        }

        public void Demo(int d)
        {
            Console.WriteLine("Demo: {0}", d);
        }

        public static void DemoStatic()
        {
            Console.WriteLine("DemoStatic");
        }
    }

    public class TestClass
    {
        public static void WriteLine() => Console.WriteLine("TestClass");
    }
}

public class Model
{
    public int X { get; set; }
}

